package boundary;

import javax.swing.JPanel;
import java.awt.GridBagConstraints;
import javax.swing.JLabel;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import boundary.Ricerca.Tipo;
import java.awt.Cursor;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;

public class RicercaMenu extends JPanel implements ActionListener {
	
	private static final long serialVersionUID = 1L;
	private JLabel titolo = null;
	private Home main;
	private JButton bCerca = null;
	private Ricerca ricerca = null;
	
	/**
	 * This is the default constructor
	 */
	public RicercaMenu(Home home) {
		super();
		this.main = home;
		initialize();
	}
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		GridBagConstraints gbcRicerca = new GridBagConstraints();
		gbcRicerca.gridx = 0;
		gbcRicerca.fill = GridBagConstraints.HORIZONTAL;
		gbcRicerca.gridy = 1;
		GridBagConstraints gbcCerca = new GridBagConstraints();
		gbcCerca.gridx = 0;
		gbcCerca.gridwidth = 1;
		gbcCerca.fill = GridBagConstraints.NONE;
		gbcCerca.insets = new Insets(5, 5, 5, 5);
		gbcCerca.gridy = 2;
		GridBagConstraints gbcTitolo = new GridBagConstraints();
		gbcTitolo.insets = new Insets(5, 5, 5, 5);
		gbcTitolo.gridy = 0;
		gbcTitolo.fill = GridBagConstraints.NONE;
		gbcTitolo.anchor = GridBagConstraints.CENTER;
		gbcTitolo.gridwidth = 1;
		gbcTitolo.gridx = 0;
		titolo = new JLabel();
		titolo.setText("Ricerca menu");
		titolo.setFont(new Font("Dialog", Font.BOLD, 20));
		this.setLayout(new GridBagLayout());
		this.setSize(293, 426);
		this.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
		this.add(titolo, gbcTitolo);
		this.add(getBCerca(), gbcCerca);
		this.add(getRicerca(), gbcRicerca);
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getSource() == bCerca) {
			if (ricerca.getCriterioRicerca() != null) main.ricercareMenu(ricerca.getCriterioRicerca());
		}
	}
	
	/**
	 * This method initializes bCerca
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBCerca() {
		if (bCerca == null) {
			bCerca = new JButton();
			bCerca.setText("Cerca");
			bCerca.setFont(new Font("Dialog", Font.BOLD, 12));
			bCerca.setMnemonic(KeyEvent.VK_UNDEFINED);
			bCerca.setIcon(new ImageIcon(getClass().getResource("/icone/search-icon.png")));
			bCerca.setCursor(new Cursor(Cursor.HAND_CURSOR));
			bCerca.setEnabled(true);
			bCerca.addActionListener(this);
		}
		return bCerca;
	}
	
	/**
	 * This method initializes ricerca
	 * 
	 * @return boundary.Ricerca
	 */
	private Ricerca getRicerca() {
		if (ricerca == null) {
			ricerca = new Ricerca(Tipo.MENU, main);
		}
		return ricerca;
	}
} // @jve:decl-index=0:visual-constraint="20,36"
